#!/usr/bin/env python
# -*- coding: utf-8 -*-

''' Author: Susana Messias n.º 6046 '''

from BeautifulSoup import BeautifulSoup
import urllib


    
'''
Counts the HTML tags.
'''
class HTMLTagCounter:
    @staticmethod
    def tagCounter(url):
        lista = []
        name = urllib.urlopen(url) 
        soup = BeautifulSoup(name)
        
        try:
            quantity = 0
            for i in soup.h1:
                quantity = quantity + 1 
                pass
            lista.append( "There are " + str(quantity) + " <H1> tags")
        except:
            lista.append( "There are no <H1> tags")
            pass

        try:
            for i in soup.h2:
                quantity = quantity + 1
                pass
            lista.append( "There are " + str(quantity) + " <H2> tags" )
        except:
            lista.append( "There are no <H2> tags")
            pass

        # Tag H3 Counter
        #################

        try:
            quantity = 0
            for i in soup.h3:
                quantity = quantity + 1
                pass
            lista.append ("There are " + str(quantity) + " <H3> tags")
        except:
            lista.append("There are no <H3> tags")
            pass

        # Tag Div Counter
        #################

        try:
            quantity = 0
            for i in soup.div:
                quantity = quantity + 1
                pass
            lista.append( "There are " + str(quantity) + " <Div> tags" )
        except:
            lista.append( "There are no <Div> tags")
            pass

        # Tag P Counter
        #################

        try:
            quantity = 0
            for i in soup.p:
                quantity = quantity + 1
                pass
            lista.append( "There are " + str(quantity) + " <P> tags" )
        except:
            lista.append( "There are no <P> tags")
            pass

        # Tag Ul Counter
        #################

        try:
            quantity = 0
            for i in soup.ul:
                quantity = quantity + 1
                pass
            lista.append( "There are " +  str(quantity) + " <UL> tags" )
        except:
            lista.append( "There are no <UL> tags")
            pass

        # Tag Ol Counter
        #################

        try:
            quantity = 0
            for i in soup.ol:
                quantity = quantity + 1
                pass
            lista.append( "There are " + str(quantity) + " <OL> tags" )
        except:
            lista.append( "There are no <OL> tags")
            pass


        return lista

